﻿using AntdUI;
using FreeSql.DataAnnotations;
using SqlSugar;
using SqlSugar.Extensions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Principal;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ZR.Model;

namespace S7SingalTool.Models.Table
{
    /// <summary>
	/// 
	/// </summary>
	[SugarTable("cks_plcblockdb")]
    [Table(Name = "cks_plcblockdb")]
    public class PlcBlockDb : BaseEntity
    {
        public PlcBlockDb()
        {

            _Operate = new AntdUI.CellLink[] {
                          new AntdUI.CellButton("save","保存",AntdUI.TTypeMini.Primary),
                        new AntdUI.CellButton("del", "删除",AntdUI.TTypeMini.Error)
                    };

        }

        AntdUI.CellLink[] _Operate;
        private CellButton writeFromButton;
        private int writeFrom;

        [SugarColumn(IsIgnore = true)]
        [Column(IsIgnore = true)]
        public AntdUI.CellLink[] Operate
        {
            get => _Operate;
            set
            {
                _Operate = value;
                OnPropertyChanged("Operate");
            }
        }

       

        /// <summary>
        /// 主键
        /// </summary>
        [SugarColumn(ColumnName = "Id", IsPrimaryKey = true, IsIdentity = true)]
        [Column(IsIdentity = true, IsPrimary = true)]
        public int Id { get; set; }

        [SugarColumn(IsIgnore = true)]
        [Column(IsIgnore = true)]
        public string WorkstationCode { get; set; }

        /// <summary>
        /// 关联Plc表Id
        /// </summary>
        [SugarColumn(ColumnName = "PlcId")]
        public int PlcId { get; set; }
        /// <summary>
        /// 数据块
        /// </summary>
        [SugarColumn(ColumnName = "BlockDb")]
        public int BlockDb { get; set; }
        /// <summary>
        /// 数据块长度
        /// </summary>
        public int BlockLength { get; set; }
        /// <summary>
        /// 写入方:1 PC、2 PLC
        /// </summary>
        [SugarColumn(ColumnName = "WriteFrom")]
        public int WriteFrom { get => writeFrom;
            set
            {
                writeFrom = value;
                
            }
        }
        /// <summary>
        /// 备注
        /// </summary>
        [SugarColumn(ColumnName = "Remark")]
        public string Remark { get; set; } = string.Empty;

        [SugarColumn(IsIgnore = true)]
        [Column(IsIgnore = true)]
        public string WriteFromText
        {
            get
            {



              return   WriteFrom switch
                {
                    1 =>"PC",
                    2 => "PLC",
                    3 => "混合",
                    _ => ""
                };
            }
        }

        [SugarColumn(IsIgnore = true)]
        [Column(IsIgnore = true)]
        public CellButton WriteFromCellText
        {
            get 
            {
               return new CellButton("",WriteFromText) {
                   //支持所有单元格控件
                   //支持所有单元格控件
                   DropDownItems = new ISelectItem[]
                        {
                             new AntdUI.SelectItem("PC",1),
                              new AntdUI.SelectItem("PLC",2),
                                new AntdUI.SelectItem("混合",3),
                        },
                   DropDownValueChanged = (value) =>
                   {
                       int badge = value.ObjToInt();
                       WriteFrom = badge;
                       OnPropertyChanged("WriteFromCellText");
                   }
               } ;

            }
            
            //set => writeFromButton = value;
        }

        [SugarColumn(IsIgnore = true)]
        [Column(IsIgnore = true)]
        public CellButton ModuleCellText
        {
            get
            {
               var text  = Module switch
                {
                    1 => "上位机",
                    2 => "AGV",
                    _ => ""
                };
                return new CellButton("",text)
                {
                    //支持所有单元格控件
                    //支持所有单元格控件
                    DropDownItems = new ISelectItem[]
                         {
                             new AntdUI.SelectItem("上位机",1),
                              new AntdUI.SelectItem("AGV",2),
                         },
                    DropDownValueChanged = (value) =>
                    {
                        int badge = value.ObjToInt();
                        Module = badge;
                        OnPropertyChanged("ModuleCellText");
                    }
                };

            }

            //set => writeFromButton = value;
        }
        /// <summary>
        /// 模块 1 上位机 2 AGV
        /// </summary>
        public int Module {  get; set; }
        /// <summary>
        /// 标记,
        /// </summary>
        [SugarColumn(ColumnName = "Flag")]
        public string Flag { get; set; } = "";
        /// <summary>
        /// 是否删除
        /// </summary>
        [SugarColumn(ColumnName = "IsDeleted")]
        public new bool IsDeleted { get; set; }



    }

}
